﻿using Admin.Model.Tool;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Admin.IService
{
    public interface IBaseServices<TEntity> where TEntity : class
    {
        #region 增删改
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model">参数实体</param>
        /// <returns>主键ID</returns>
        Task<int> Insert(TEntity model);

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model">参数实体</param>
        /// <param name="fields">新增的字段</param>
        /// <returns>主键ID</returns>
        Task<int> Insert(object param, string[] fields);
        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        Task<int> Insert(List<TEntity> list);
        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="list"></param>
        /// <param name="fields">新增的字段</param>
        /// <returns></returns>
        Task<int> Insert(List<TEntity> list, string[] fields);
        /// <summary>
        /// 根据主键修改
        /// </summary>
        /// <param name="model">参数实体</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Edit(TEntity model);

        /// <summary>
        /// 根据主键修改部分字段 
        /// </summary>
        /// <param name="model">参数实体</param>
        /// <param name="fields">修改的字段</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Edit(object param, string[] fields);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="fields">修改的字段</param>
        /// <param name="sqlWhere">修改的条件:参数化写法，值放param里传</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Edit(object param, string[] fields, string sqlWhere);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Code">主键ID</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Delete(int Code);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Delete(object param, string sqlWhere);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids">主键ids 多个逗号隔开</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Delete(string ids);
        #endregion

        #region 查询
        /// <summary>
        /// 根据主键查询单条
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Code">主键ID</param>
        /// <param name="cacheEntity"></param>
        /// <returns>单条数据</returns>
        Task<TEntity> Get(int Code, CacheModel cacheEntity = null);

        /// <summary>
        /// 单条查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <param name="showFields">显示字段</param>
        /// <param name="cacheEntity">是否缓存实体</param>
        /// <returns>单条数据</returns>
        Task<TEntity> Get(object param, string sqlWhere, string showFields = "*", CacheModel cacheEntity = null);

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheEntity">缓存实体</param>
        /// <returns>数据列表</returns>
        Task<IEnumerable<TEntity>> GetList(CacheModel cacheEntity = null);

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <param name="orderBy">排序：Id desc,Code asc</param>
        /// <param name="showFields">显示字段</param>
        /// <param name="cacheEntity">是否缓存实体</param>
        /// <returns>数据列表</returns>
        Task<IEnumerable<TEntity>> GetList(object param, string sqlWhere, string orderBy, string showFields = "*", CacheModel cacheEntity = null);

        /// <summary>
        /// 获取前几条数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="TopNumber">数量</param>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <param name="orderBy">排序：Id desc,Code asc</param>
        /// <param name="showFields">显示字段</param>
        /// <param name="cacheEntity">是否缓存实体</param>
        /// <returns>数据列表</returns>
        Task<IEnumerable<TEntity>> GetTopList(int TopNumber, object param, string sqlWhere, string orderBy, string showFields = "*", CacheModel cacheEntity = null);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page">当前页</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="param">条件参数</param>
        /// <param name="sqlWhere">条件</param>
        /// <param name="orderBy">排序</param>
        /// <param name="showFields">显示字段</param>
        /// <param name="cacheEntity">缓存</param>
        /// <returns></returns>
        Task<IEnumerable<TEntity>> GetPage(int page, int pageSize, object param = null, string sqlWhere = "", string orderBy = "", string showFields = "*", CacheModel cacheEntity = null);
        #endregion

        #region  其他
        /// <summary>
        /// 检测是否存在
        /// </summary>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <returns>true or false</returns>
        Task<bool> IsExist(object param, string sqlWhere);

        /// <summary>
        /// 查询总数量
        /// </summary>
        /// <param name="param">参数实体</param>
        /// <param name="sqlWhere">where条件，参数化写法，值放param里传</param>
        /// <returns>数量</returns>
        Task<int> GetCount(object param, string sqlWhere);
        #endregion
    }
}
